#!/bin/bash
#
#   spice_indent
#       This utility was used by Jeremy White to attempt to make the
#   x11spice code largely conform to the Spice Project Coding Style.
#   It's preserved here as a form of documentation.

# Note: Spice is now relaxed about function declarations,
#       and allow either style, e.g.
#  char *func()  or
#
#  char *
#  func()
#   That requires calling indent with some thoughtfulness
# By default, it will break procedure types onto newlines
#   which is not always the desired behavior
# Add  --dont-break-procedure-type  to change that


if [ $# -lt 1 ] ; then
    echo Error: specify at least one file to process with indent
    echo Usage:
    echo '  spice_indent [ extra-options ] <filename> [ filename... ]'
    echo 'A useful option is --dont-break-procedure-type'
    exit 1
fi

# Run the indent command with no version control; we're using git after all...
VERSION_CONTROL=none \
indent \
  --no-space-after-function-call-names \
  --braces-after-func-def-line \
  --braces-on-if-line \
  --braces-on-struct-decl-line \
  --line-length 100 \
  --no-space-after-parentheses \
  --no-tabs \
  --case-indentation 0 \
  --tab-size 4\
  --indent-label 0\
  --indent-level 4\
  --declaration-indentation 1 \
  --space-after-for \
  --space-after-while \
  --space-after-casts \
  --space-after-if \
  --cuddle-else \
  -cd0 \
  -c0 \
  -T agent_t \
  -T SpiceCharDeviceInstance \
  -T SpiceChannelEventInfo \
  -T QXLInstance \
  -T QXLWorker \
  -T QXLDevInitInfo \
  -T VDAgentMonitorsConfig \
  -T SpiceTimer \
  -T SpiceKbdInstance \
  -T SpiceTabletInstance \
  -T SpiceWatch \
  -T GIOChannel \
  -T spice_t \
  -T options_t \
  -T uint8_t  \
  -T uint16_t  \
  -T uint32_t  \
  -T scan_type_t \
  -T scan_report_t \
  -T scanner_t \
  -T session_t \
  -T shm_image_t \
  -T spice_release_t \
  -T xcb_connection_t \
  -T xcb_xfixes_cursor_notify_event_t \
  -T xcb_damage_notify_event_t \
  -T xcb_damage_notify_event_t \
  -T xcb_configure_notify_event_t \
  -T xcb_screen_t \
  -T display_t \
  -T gui_t  \
  -T GKeyFile \
  -T gchar \
  -T xdummy_t \
  -T x11spice_server_t \
  -T test_t \
  -T Bool \
  -T shm_segment_t \
  -T GtkWidget \
  -T ssl_options_t \
  -T GAsyncQueue \
  "$@"
